package v;
import java.util.*;
public class yunxing {
 Collection s=new ArrayList();
 public void yunxing() {
	 System.out.println("**笔记本**");
	 System.out.println("**1添加信息**");
	 System.out.println("**2删除信息**");
	 System.out.println("**3修改信息**");
	 System.out.println("**4查找信息**");
	 System.out.println("**5退出**");
	 System.out.println("**输入操作**");
	 Scanner in=new Scanner(System.in);
	 int inDate=in.nextInt();
	 switch(inDate){
	 case 1:addData();break;//添加功能，返回x`
	 case 2:delData();break;//删除功能
	 case 3:upData();System.out.println("**已完成修改。**\n");yunxing();
	 case 4:System.out.print("所需要查询日期是：");searchData();yunxing();
	 case 5:System.out.println("已退出！");System.exit(0);
	 default:System.out.println("输入无效，请重新输入~");yunxing();
	 }
 }
 private String indata() {
	 System.out.print("请输入日期：");
	 Scanner in1=new Scanner(System.in);
	 String inData1=in1.next();
	 return inData1;
 }
 private String inevent() {
	 System.out.println("请输入事件:");
	 Scanner in2=new Scanner(System.in);
	 String inDate2=in2.next();
	 return inDate2;
 }
 private void addData() {
	 String a1=indata();
	 String a2=inevent();
	 s.add(new biji(a1,a2));
	 System.out.println("**添加成功！**\n");
	 yunxing();
 }
 private void delData() {
	 biji del=searchData();
	 if(del!=null) {
		 s.remove(del);
		 System.out.println("**信息已删除~**\n");
	 }
	 yunxing();
 }
 private void upData() {
	 biji up=searchData();
	 System.out.println("1修改日期");
	 System.out.println("2修改信息");
	 System.out.println("输入操作：");
	 Scanner in=new Scanner(System.in);
	 int upData=in.nextInt();
	 switch(upData){
	 case 1:
		 System.out.println("**输入新日期**");
	     Scanner in1=new Scanner(System.in);
	     String upData1=in1.next();
	     up.setdate(upData1);
	     break;
	 case 2:
         System.out.println("**输入新的信息**");		 
	     Scanner in2=new Scanner(System.in);
	     String upData2=in2.next();
	     up.setevent(upData2);
	     break;
	 }
 }
 private biji searchData() {
	 String a3=indata();
	 Iterator it=s.iterator();
	 while(it.hasNext()) {
		 biji sd=(biji)it.next();
		 if(sd.getdate().equals(a3)) {
			 System.out.println("日期："+sd.getdate()+"   "+"信息事件"+sd.getevent());
			 return sd;
		 }
	 }
	 System.out.println("**没有该日期**\n");
	 yunxing();
	 return null;
 }
 public static void main(String[]args) {
	 yunxing note=new yunxing();
	 note.yunxing();
 }
}
